Skip to content

[16.0][FIX] budget_appropriation_summary: reconcile summary totals with compilation#693

Open
n3n wants to merge 3 commits into
16.0from
16.0-fix-budget_appropriation_summary-calc
Open

[16.0][FIX] budget_appropriation_summary: reconcile summary totals with compilation#693
n3n wants to merge 3 commits into
16.0from
16.0-fix-budget_appropriation_summary-calc

Conversation

@n3n
Copy link
Copy Markdown
Member

@n3n n3n commented Apr 22, 2026

Summary

Summary reports on /budget_appropriation_summary did not match master totals because every F-report (F2/F4P/F4W/F5P/F5W/F7W/F8W/F9W/F10W/F11W) aggregated raw line balances, bypassing the compilation layer and its amount_net semantics. All summary models now iterate summary.compilation_ids via two new helpers on budget.appropriation.compilationiter_signed_lines() (subtracts deduct_line_ids) and top_level_department_id() — so per-compilation sums equal amount_net and department attribution follows the compilation. Also fixes the prefix in parent_path substring collision in F5W/F8W/F9W and the reserve-fund vs activity-plan double-count in F9W.

Test plan

  • Open /budget_appropriation_summary/<id>/html and verify each F-report grand total matches the master amount_revenue_total/amount_expense_total
  • Test with an appropriation that has deduct_line_ids and confirm summaries net out the deduction
  • Check F9W with a compilation containing 07020 lines — reserve-fund column shows them once, activity-plan column does not

n3n added 3 commits April 22, 2026 17:57
…th compilation amount_net

Summary reports on the /budget_appropriation_summary portal page did not
match the master totals because every F-report (F2/F4P/F4W/F5P/F5W/F7W/
F8W/F9W/F10W/F11W) aggregated raw line balances, ignoring deduct lines
and the compilation layer entirely.

Refactor every summary model to iterate summary.compilation_ids and use
two new helpers on budget.appropriation.compilation:

- iter_signed_lines(budget_type): yields (line, sign) where deduct_line_ids
  contribute -1 so per-compilation sums equal amount_net.
- top_level_department_id(): returns the compilation's top-level ancestor
  department so attribution follows the compilation, not the line.

Additional fixes:
- F5W/F8W/F9W: replace `prefix in parent_path` substring match with
  `parent_path.startswith(prefix)` to stop id "10/" colliding with "110/".
- F9W: make reserve-fund and activity-plan columns mutually exclusive so
  07020 lines no longer count into both columns.
…evenue reports

Revenue F-reports (F2/F4P/F4W) must show gross revenue (ก่อนหักโอน).
The previous commit incorrectly subtracted deduct_line_ids for revenue
summaries, which represents transfers out and should not reduce the
revenue figures shown in the F-reports.

Iterate revenue_appropriation_ids.line_ids only on the revenue summaries.
Expense summaries continue to use iter_signed_lines to net out deducts
because amount_expense_total uses amount_net.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant